package com.acwing.partition3;

import java.io.*;

/**
 * @author `RKC`
 * @date 2022/2/14 18:40
 */
public class AC243一个简单的整数问题2_线段树 {

    private static final int N = 100010;
    private static Node[] tr = new Node[N << 2];
    private static int[] nums = new int[N];

    private static int n = 0, m = 0;

    private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    private static final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        String[] ss = reader.readLine().split(" ");
        n = Integer.parseInt(ss[0]);
        m = Integer.parseInt(ss[1]);
        ss = reader.readLine().split(" ");
        for (int i = 1; i <= n; i++) nums[i] = Integer.parseInt(ss[i - 1]);
        build(1, 1, n);
        while (m-- > 0) {
            ss = reader.readLine().split(" ");
            int l = Integer.parseInt(ss[1]), r = Integer.parseInt(ss[2]);
            if (ss[0].charAt(0) == 'Q') {
                writer.write(query(1, l, r) + "\n");
            } else {
                int d = Integer.parseInt(ss[3]);
                modify(1, l, r, d);
            }
        }
        writer.flush();
    }

    private static void pushup(int u) {
        tr[u].sum = tr[u << 1].sum + tr[u << 1 | 1].sum;
    }

    private static void pushdown(int u) {
        //父节点来更新子节点的信息，如果父节点有懒标记，则下沉到子节点
        Node root = tr[u], left = tr[u << 1], right = tr[u << 1 | 1];
        if (root.add != 0) {
            left.sum += (left.r - left.l + 1) * root.add;
            left.add += root.add;
            right.sum += (right.r - right.l + 1) * root.add;
            right.add += root.add;
            root.add = 0;
        }
    }

    private static long query(int u, int l, int r) {
        if (l <= tr[u].l && r >= tr[u].r) return tr[u].sum;
        pushdown(u);
        int mid = tr[u].l + tr[u].r >> 1;
        long res = 0;
        if (l <= mid) res += query(u << 1, l, r);
        if (r > mid) res += query(u << 1 | 1, l, r);
        return res;
    }

    private static void modify(int u, int l, int r, int d) {
        if (l <= tr[u].l && r >= tr[u].r) {
            tr[u].sum += (long) (tr[u].r - tr[u].l + 1) * d;
            tr[u].add += d;
        } else {
            pushdown(u);
            int mid = tr[u].l + tr[u].r >> 1;
            if (l <= mid) modify(u << 1, l, r, d);
            if (r > mid) modify(u << 1 | 1, l, r, d);
            pushup(u);
        }
    }

    private static void build(int u, int l, int r) {
        if (l == r) tr[u] = new Node(l, r, nums[l], 0);
        else {
            tr[u] = new Node(l, r);
            int mid = l + r >> 1;
            build(u << 1, l, mid);
            build(u << 1 | 1, mid + 1, r);
            pushup(u);
        }
    }

    private static class Node {
        private int l, r;
        private long sum, add;

        public Node(int l, int r) {
            this.l = l;
            this.r = r;
        }

        public Node(int l, int r, long sum, long add) {
            this.l = l;
            this.r = r;
            this.sum = sum;
            this.add = add;
        }
    }
}
